//
//  TaskToastView.m
//  ZITHER
//
//  Created by 吴凡 on 2019/2/25.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "TaskToastView.h"

@implementation TaskToastView

- (void)awakeFromNib {
    [super awakeFromNib];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushWebAction:)];
    [self addGestureRecognizer:tap];
    self.userInteractionEnabled = YES;
    
}
- (void)setData:(TaskModel *)model {
    NSInteger type;
    if (model.phoneOrEmail) {
        type = 1;
    } else {
        type = 2;
    }
    
    switch (type) {
        case 1:
            _topLabel.text = [NSString stringWithFormat:@"%@注册完成，获取奖金",model.phoneOrEmail];
            _moneyLabel.text = [NSString stringWithFormat:@"%@",[self limitFloatValue:[model.accumulateMoney floatValue]]];
            break;
        case 2:
            _topLabel.text = [NSString stringWithFormat:@"已登入%@天，奖金已解锁，可提现",model.step];
            _moneyLabel.text = [NSString stringWithFormat:@"%@",[self limitFloatValue:[model.money floatValue]]];
            _bottomLabel.text = @"邀请好友 能获得更多奖金";
            break;
        default:
            break;
    }
}
- (NSString *)limitFloatValue:(CGFloat)value{
    if (fmodf(value, 1)==0) {//如果有一位小数点
        return [NSString stringWithFormat:@"￥%.0f",value];
    } else if (fmodf(value*10, 1)==0) {//如果有两位小数点
        return [NSString stringWithFormat:@"￥%.1f",value];
    }else {
        return [NSString stringWithFormat:@"￥%.2f",value];
    }
}
- (void)pushWebAction:(id)sender {
    if (_pushWebBlock) {
        _pushWebBlock();
    }
}
- (IBAction)closeBtn:(id)sender {
    if (_cancelBlock) {
        _cancelBlock();
    }
}

@end
